#include <cstdio> //using namespace std;
#include <iostream>
#include <string>
#include <map>
using namespace std;
#define DEBUG
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}

inline void write(long long x)
{
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}
string str;
map<char, int> st;

void init()
{
    cin >> str;
    st.clear();
}

void solve()
{
    init();
    int ret=2;
    bool zm=0, num=0, sp=0;
    for(char ch:str)
    {
        st[ch]++;
    }
    for(auto pci:st)
    {
        auto ch=pci.first; 
        auto cnt=pci.second;
        if(('A'<=ch&&ch<='Z')||('a'<=ch&&ch<='z'))
            zm=1;
        else if('0'<=ch&&ch<='9')
            num=1;
        else sp=1;
        if(cnt>2) ret=1;
        // printf("%d %d %d %c %d %d\n", zm, num, sp, ch, cnt, ret);
    }
    if(!(zm&&num&&sp)) ret=0;
    write(ret); puts("");
}

signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif

    int T=1; scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}